package deibay.server.commands;

import deibay.datamodel.Item;
import deibay.messages.Message;
import deibay.messages.RequestItemDetailsMsg;
import deibay.messages.SendItemDetailsMsg;
import deibay.server.ServerManager;
import deibay.server.eventargs.SendMessageEventArg;
import deibay.server.events.SendMessageEvent;
import deibay.users.User;

public class RequestItemDetailsCommand extends Command{

	
	public RequestItemDetailsCommand(User user, Message msg) {
		super(user, msg);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void execute() {		
		String itemID = ((RequestItemDetailsMsg)message).getItem();
		Item item = ServerManager.getInstance().getDataManager().getItem(itemID);

		SendItemDetailsMsg msg = new SendItemDetailsMsg(SendItemDetailsMsg.class.getSimpleName(), item);		
		ServerManager.getInstance().getEventManager().fireEvent(new SendMessageEvent(new SendMessageEventArg(this.user.getId(), msg)));

	}
}
